package servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "JSPServlet", value = "/JSPServlet")
public class JSPServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        request.setCharacterEncoding("utf-8");
        request.setAttribute("myName", "小郭");
        request.setAttribute("myAge", 20);
        HttpSession session = request.getSession();
        session.setAttribute("myAge",18);
        ServletContext context = request.getServletContext();
        context.setAttribute("mySchool","中原工");
        Cookie cookie = new Cookie("myAddress","郑州");
        response.addCookie(cookie);
//        cookie要有转发
        request.getRequestDispatcher("/demo2.jsp").forward(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        doGet(request, response);
    }
}
